package com.gpnu.crm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gpnu.crm.domain.Department;
import com.gpnu.crm.mapper.DepartmentMapper;
import com.gpnu.crm.query.QueryObject;
import com.gpnu.crm.service.IDepartmentService;

@Service
public class DepartmentServiceImpl implements IDepartmentService {

	@Autowired
	private DepartmentMapper departmentMapper;

	public DepartmentServiceImpl() {
	}

	public void saveOrUpdate(Department entity) {
		if (entity.getId() == null) {
			departmentMapper.insert(entity);
		} else {
			departmentMapper.updateByPrimaryKey(entity);
		}
	}

	public void delete(Long id) {
		departmentMapper.deleteByPrimaryKey(id);
	}

	public List<Department> list() {
		return departmentMapper.selectAll();
	}

	public PageInfo<Department> query(QueryObject qo) {
		PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
		List<Department> list = departmentMapper.selectForList(qo);
		return new PageInfo(list);
	}

}
